#include "Bonus.h"
#include "Level.h"

Bonus::Bonus(int x, int y, TYPE type) : speed(2), destroyed(false), type(type)
{
    speed = 1 + rand() % 3;
    switch(type)
    {
        case BIGGERPANEL:
            bonusSprite.SetTexture(rm->getTexture("biggerPanelBonus.png")); break;
        case SMALLERPANEL:
            bonusSprite.SetTexture(rm->getTexture("smallerPanelBonus.png")); break;
        case PAUSE:
            bonusSprite.SetTexture(rm->getTexture("pauseBonus.png")); break;
        case LIVE:
            bonusSprite.SetTexture(rm->getTexture("liveBonus.png")); break;
        case ACID:
            bonusSprite.SetTexture(rm->getTexture("acidBonus.png")); break;
        case BALL:
            bonusSprite.SetTexture(rm->getTexture("ballBonus.png")); break;
    }
    bonusSprite.SetPosition(x, y);
}

void Bonus::update()
{
    bonusSprite.Move(0, speed);
    if(bonusSprite.GetGlobalBounds().Top > HEIGHT)
        destroyed = true;
}

void Bonus::draw(sf::RenderWindow* Window) const
{
    Window->Draw(bonusSprite);
}

void Bonus::onCatch(Level* level)
{
    switch(type)
    {
        case BIGGERPANEL:
        {
            points += 20;
            tBiggerPanelBonuses++;
            if(level->panel.size == 2)
            {
                level->panel.panelSprite = sf::Sprite(rm->getTexture("biggerPanel.png"));
                level->panel.size = 3;
                return;
            }
            else if(level->panel.size == 1)
            {
                level->panel.panelSprite = sf::Sprite(rm->getTexture("Panel.png"));
                level->panel.size = 2;
                return;
            }
            break;
        }
        case SMALLERPANEL:
        {
            points -= 10;
            tSmallerPanelBonuses++;
            if(level->panel.size == 2)
            {
                level->panel.panelSprite = sf::Sprite(rm->getTexture("smallerPanel.png"));
                level->panel.size = 1;
                return;
            }
            else if(level->panel.size == 3)
            {
                level->panel.panelSprite = sf::Sprite(rm->getTexture("Panel.png"));
                level->panel.size = 2;
                return;
            }
            break;
        }
        case PAUSE:
        {
            pauseCount++;
            tPauseBonuses++;
            break;
        }
        case LIVE:
        {
            points += 50;
            lives++;
            tLiveBonuses++;
            break;
        }
        case ACID:
        {
            for(auto itr = level->balls.begin(); itr != level->balls.end(); itr++)
                (*itr)->makeAcid();

            tAcidBonuses++;
            break;
        }
        case BALL:
        {
            points += 20;
            level->addBall();
            tBallBonuses++;
        }
    }
    destroyed = true;
}
